#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: modify_rpsType_to_array.py
# @time: 2021/4/26 10:56
# @desc:
from .utils.utils import read_json, save_json

history_clamp = read_json("../data/export_data/history_clamp.json")

for i in history_clamp:
    temp_list = []
    if i["number"] == "2021010000000216":
        print(i)
    if "rpsType" in i['tag'] and type(i['tag']['rpsType']) == dict:
        for j in i['tag']['rpsType'].items():
            if j[1] != None:
                temp_list.append(j[1])
        i['tag']['rpsType'] = temp_list

    if "rpsType" in i["tag"] and i["tag"]["rpsType"] is not None:
        try:
            if None in i["tag"]["rpsType"]:
                i["tag"]["rpsType"].remove(None)
        except:
            print(i["tag"])

        if None == i["tag"]["rpsNumber"] or "" == i["tag"]["rpsNumber"]:
            i["tag"]["rpsNumber"] = 0
        else:
            i["tag"]["rpsNumber"] = int(i["tag"]["rpsNumber"])

        if None == i["tag"]["airNumber"] or "" == i["tag"]["airNumber"]:
            i["tag"]["airNumber"] = 0
        else:
            i["tag"]["airNumber"] = int(i["tag"]["airNumber"])

save_json(history_clamp, "../data/export_data/history_clamp_new.json")
